<?php
include_once "config.php";
include_once "utils.php";

$run = true;
foreach (Team::getTeams() as $id=>$team)
{
    if (!$run) break;
    $run = false;

    $html = Util::getContentsCurl("http://pesstatsdatabase.com/PSD/Players.php?Club=" . $id);
    $dom = new DOMDocument();
    @$dom->loadHTML($html);

    $table  = $dom->getElementsByTagname('table');
    $tr     = $table->item(2)->getElementsByTagname('tr');

    $out        = array();
    $numberArr  = array();
    $nameArr    = array();
    for ($i=3; $i<$tr->length; $i++)
    {
        $td         = $tr->item($i)->getElementsByTagname('td');
        $line       = $td->item(0)->nodeValue . "\n";
        $explode    = explode('-', $line);
        $number     = trim($explode[0]);
        $name       = trim($explode[1]);

        $numberArr[]    = $number;
        $nameArr[]      = $name;
        /*
        $out[]  = array(
            'number'    => $number,
            'name'      => $name
        );
        */
    }
    $out = array('name' => $nameArr, 'number' => $numberArr);
    //Util::saveJson($out, FOLDER_DATA . $id);
    //print_r($out);
    //echo "\n\n";
}
